package cpm.cloud.controller;

import com.test.entities.HandDepartments;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @author dell
 */
@RestController
@RequestMapping("/consumer")
public class ConsumerController {

    private static final String REST_URL_PREFIX = "http://localhost:8001";

    @Autowired
    private RestTemplate restTemplate;

//    @RequestMapping(value="/consumer/dept/list")
//    public List<Dept> list()
//    {
//        return restTemplate.getForObject(REST_URL_PREFIX+"/dept/list",List.class);
//    }

    @RequestMapping("/dept/get/{id}")
    public HandDepartments findById(@PathVariable("id")Long id){
        return restTemplate.getForObject(REST_URL_PREFIX+"/dept/get/"+id,HandDepartments.class);
    }

    @SuppressWarnings("unchecked")
    @RequestMapping("/dept/list")
    public List<HandDepartments> findAll(){
        return restTemplate.getForObject(REST_URL_PREFIX+"/dept/list",List.class);
    }

    @RequestMapping("/dept/add")
    public HandDepartments add(HandDepartments departments){
        return restTemplate.getForObject(REST_URL_PREFIX+"/dept/add",HandDepartments.class);
    }


//    @PostMapping("/dept/add")
//    public HandDepartments add(@RequestBody HandDepartments departments){
//        return deptService.addDept(departments);
//    }
//


}
